class C:

    def __init__(self):
        self._x = 250

    def getx(self):
        return self._x

    def setx(self, value):
        self._x = value

    def delx(self):
        del self._x

    x = property(getx, setx, delx)


c = C()
print(c.x)
c.x = 520
print(c.__dict__)  # {'_x': 520}
del c.x
print(c.__dict__)  # {}

# TODO 把上面的改为描述附的实现方式

print("======" * 20)


class EDescriptor:

    def __get__(self, instance, owner):
        return instance._x

    def __set__(self, instance, value):
        instance._x = value

    def __delete__(self, instance):
        del instance._x


class E:

    def __init__(self, x=250):
        self._x = x

    x = EDescriptor()


e = E()

print(e.x)

e.x = 520
print(e.x)
print(e.__dict__)
# {'_x': 520}
del e.x
print(e.__dict__)
# {}
